/*
** 2591.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Sat Oct 11 21:44:35 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/
/*
 * EXPERIENCE: needs high efficiency number generating function....
 */

/* #include "2591.h" */
#include <stdio.h>
#include <stdlib.h>

int main()
{
     int *set_num = (int*)malloc(10000001*sizeof(int));
     int tail, i, j, k;
     int tmp;
     int test;
     
     for(set_num[0] = tail = 1, i = 0; tail < 10000001; i++){
	  tmp = 2 * set_num[i] + 1;
	  for(j = tail; set_num[j-1] > tmp; j--);
	  if (set_num[j-1] != tmp){
	       for(k = tail; k > j; k--)
		    set_num[k] = set_num[k-1];
	       set_num[j] = tmp;
	       tail++;
	  }

	  tmp = 3 * set_num[i] + 1;
	  for(j = tail; set_num[j-1] > tmp; j--);
	  if (set_num[j-1] != tmp){
	       for(k = tail; k > j; k--)
		    set_num[k] = set_num[k-1];
	       set_num[j] = tmp;
	       tail++;
	  }
     }

     while(scanf("%d", &test) != EOF)
	  printf("%d\n", set_num[test - 1]);

     return 0;
}

	  
	  
